package handler

import (
	"context"
	"device_mq_handler/internal/pkg/instance"
	"device_mq_handler/internal/protocol/jt808/holder"
	position_up "device_mq_handler/internal/protocol/jt808/model/position-up"
	"device_mq_handler/internal/protocol/jt808/producer"
	"encoding/json"
	"github.com/streadway/amqp"
	"go.uber.org/zap"
)

func init() {
	holder.RegisterHandler(512, PositionUp)
}

func PositionUp(ctx context.Context, data []byte, delivery *amqp.Delivery) error {
	req := &position_up.Req{}
	err := json.Unmarshal(data, req)
	if err != nil {
		return err
	}
	instance.GetAppLog().Info("位置信息解析成功", zap.Float64("经度", req.Body.Pos.Latitude))
	// 测试发送消息到队列中
	producer.Publish(ctx, "", "jt808.common.reader", false, false, amqp.Publishing{DeliveryMode: amqp.Persistent, Body: data})
	return nil
}
